package org.jeecg.modules.demo.xxljob;/**
 * @author yxx
 * @create 2022-10-31 19:10
 * @Description:TODO
 * @author:yxx
 * @date:2022年10月2022/10/31日19:10
 */

/**
 *@Description:TODO
 *@author:yxx
 *@date:2022年10月2022/10/31日19:10
 */

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.ch.entity.ChParameter;
import org.jeecg.modules.demo.ch.service.IChParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * xxl-job定时任务测试
 */
@Component
@Slf4j
public class AssociateJobHandler {

    @Autowired
    private IChParameterService iChParameterService;

    /**
     * 简单任务
     *
     * 测试：无token调用feign接口
     *
     * @param params
     * @return
     */
    @XxlJob(value = "updateSerialNumToZero")
    public ReturnT<String> updateSerialNumToZero(String params) {
        String jobParam = XxlJobHelper.getJobParam();
        Map<String, Object> map = (Map<String, Object>) JSON.parse(jobParam);
        String majorCategories = (String) map.get("major_categories");
        String littleClass = (String) map.get("little_class");
        String valueStr = (String) map.get("value_str");
        XxlJobHelper.log("jeecgBoot自定义的updateSerialNumToZero传入的majorCategories{},littleClass{},valueStr{}", majorCategories, littleClass, valueStr);
        LambdaUpdateWrapper<ChParameter> chParameterLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        chParameterLambdaUpdateWrapper.eq(ChParameter::getMajorCategories, majorCategories)
                .eq(ChParameter::getLittleClass, littleClass)
                .set(ChParameter::getValueStr, valueStr);
        boolean update = iChParameterService.update(chParameterLambdaUpdateWrapper);
        if (!update){
            return ReturnT.FAIL;
        }
        return ReturnT.SUCCESS;
    }
}
